package com.shishuo.cms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shishuo.cms.constant.GoodsExceptionConstant;
import com.shishuo.cms.dao.UserScanGoodsDao;
import com.shishuo.cms.entity.UserScanGoods;
import com.shishuo.cms.entity.vo.PageVo;
@Service
public class UserScanGoodsService extends BaseService<UserScanGoods, Long> {
	private UserScanGoodsDao userScanGoodsDao;

	@Autowired
	public void setUserScanGoodsDao(UserScanGoodsDao userScanGoodsDao) {
		super.setBaseDao(userScanGoodsDao);
		this.userScanGoodsDao = userScanGoodsDao;
	}
	/**
	 * 根据用户编号分页获取收藏的产品
	 * @param pageNum
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public PageVo<UserScanGoods> getAllListPage(int pageNum,long userId)
			throws Exception {
		PageVo<UserScanGoods> pageVo = new PageVo<UserScanGoods>(
				pageNum);
		List<UserScanGoods> list = userScanGoodsDao.getAllList(
				pageVo.getOffset(), pageVo.getRows(), userId);
		pageVo.setList(list);
		pageVo.setCount(userScanGoodsDao.getAllListCount(userId));
		return pageVo;
	}

	public void saveUserScanGoods(UserScanGoods userScanGoods) throws Exception {
		if (null==userScanGoods) {
			throw new Exception(GoodsExceptionConstant.SAVE_FAV_GOODS_ERROR_GOODS_IS_NULL);
		}
		insert(userScanGoods);
	}
}
